package com.TencentMusic.interview;

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

/**
 * @author ZhangyiA
 * @describe: 优先队列 和 HashSet 结合使用
 * @date 2021/07/03
 *
 * PriorityQueue<Integer> p = new PriorityQueue<>(((o1, o2) -> o2 - o1)); // 实现降序
 */

public class Two_CunningEmployer {

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        Set<Integer> set = new HashSet<>();
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(); // 默认是升序
        for(int i = 0 ; i < n ; i ++){
            int slary = input.nextInt();
            if(set.add(slary)){
                priorityQueue.offer(slary);
            } else {
                priorityQueue.remove(slary);
            }
        }
        if(priorityQueue.size() == 0) System.out.println(-1);
        else System.out.println(priorityQueue.poll());
    }

}
